<!DOCTYPE html>
<html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>代码生成</title>
    <link rel="stylesheet" type="text/css" th:href="@{/layui/css/layui.css}">
</head>
<body>


<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">相册名称：</label>
                        <div class="layui-input-inline mr0">
                            <input name="albumName" id="albumName" placeholder="请输入相册名称" type="text" class="layui-input"/>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
                    </div>
                </div>
            </div>
            <!-- 表格顶部操作列 -->
            <script type="text/html" id="generator-toolbar">
                <div class="layui-btn-container">
                    <button id="btn1Add"  class="layui-btn  layui-btn-sm" lay-event="add">
                        <i class="layui-icon">&#xe654;</i>添加
                    </button>
<!--                    <button id="btnDel" class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">-->
<!--                        <i class="layui-icon">&#xe640;</i>删除-->
<!--                    </button>-->
<!--                    <button id="btnExp" class="layui-btn layui-btn-normal layui-btn-sm" >-->
<!--                        <i class="layui-icon">&#xe67d;</i>导出-->
<!--                    </button>-->
                </div>
            </script>
            <table class="layui-table" id="generatorTable" lay-filter="generatorTable"></table>

        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="tableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs table-icon-font" lay-tips="生成代码" lay-event="add">生成代码</a>
    <!--<a class="layui-btn layui-btn-xs" lay-event="auth">权限分配</a>-->
</script>
<script type="text/javascript" th:src="@{/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/js/jquery-3.2.1.min.js}"></script>
<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'util'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        //渲染表格
        table.render({
            elem: '#generatorTable',
            title:"",
            url: '/generator/generatorTable',
            toolbar: false,
            where: $('form').serialize(),
            page: true,
            cols: [
                [
                    {type: 'numbers', title:'序号'},
                    {type: 'checkbox'},
                    {title: '表名称', field: 'tableName', align: 'center', valign: 'middle'},
                    {title: '表描述', field: 'comments', align: 'center', valign: 'middle'},
                    {title: '创建时间', field: 'createTime', align: 'center', valign: 'middle'},
                    {title: '修改时间', field: 'updateTime', align: 'center', valign: 'middle'},
                    {align: 'center', toolbar: '#tableBar',minWidth:170, title: '操作'}
                ]
            ]
        });


        //头工具栏事件
        table.on('toolbar(generatorTable)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    showAddModel();
                    break;
                case 'del':
                    if (checkStatus.data.length == 0) {
                        layer.msg('请选择要删除的数据', {icon: 2});
                    } else {
                        var data = checkStatus.data;
                        var id_str="";
                        for (var i=0;i<data.length;i++){
                            id_str +=data[i].id+",";
                        }
                        id_str = id_str.substr(0, id_str.length-1);
                        layer.confirm('真的删除么', function(index){
                            layer.load(2);
                            $.post('generator/batchDelete', {
                                departIds: id_str
                            }, function (data) {
                                layer.closeAll('loading');
                                if (data.code == 200) {
                                    layer.msg(data.msg, {icon: 1});
                                    obj.del();
                                    // table.reload('Table');
                                } else {
                                    layer.msg(data.msg, {icon: 2});
                                }
                            });
                        });
                    }
                    break;
                case 'export':
                    if (checkStatus.data.length == 0) {
                        layer.msg('请选择要导出的数据', {icon: 2});
                    } else {
                        table.exportFile(ins1.config.id, checkStatus.data, 'xls');
                    }
                    break;
            };
        });


        // 搜索按钮点击事件
        $('#btnSearch').click(function () {
            table.reload('roleTable', {where: $('form').serialize()});
        });

        // 工具条点击事件
        table.on('tool(generatorTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'add') { //修改
                showAddModel(data);
            }
        });


        // 显示添加弹窗
        function showAddModel(data) {
            $.post("/generator/createGenerate",
                data
            , function (data) {
                layer.closeAll('loading');
                if (data.code == 200) {
                    top.layer.msg(data.msg, {icon: 1});
                } else {
                    top.layer.msg(data.msg, {icon: 2});
                }
            });
            return false;
        }

    });

</script>
</body>

</html>